import junit.framework.TestCase;

import de.unibi.comet.ac.CharacterDistribution;

public class CharacterDistributionTest extends TestCase {

	public void testBasics() {
		CharacterDistribution dist = new CharacterDistribution();
		dist.set('a', 0.1);
		dist.set('c', 0.2);
		dist.set('g', 0.3);
		dist.set('t', 0.4);
		assertEquals(0.4, dist.probability('t'), 1e-8);
		assertEquals(0.3, dist.probability('g'), 1e-8);
		assertEquals(0.2, dist.probability('c'), 1e-8);
		assertEquals(0.1, dist.probability('a'), 1e-8);
		assertEquals(0.0, dist.probability('A'), 1e-8);
		assertEquals(0.0, dist.probability('B'), 1e-8);
		assertEquals(0.0, dist.probability('z'), 1e-8);
	}

	public void testBasics2() {
		int[] freq = new int[256];
		freq[(int)'a']=100;
		freq[(int)'c']=200;
		freq[(int)'g']=300;
		freq[(int)'t']=400;
		CharacterDistribution dist = new CharacterDistribution(freq);
		assertEquals(0.4, dist.probability('t'), 1e-8);
		assertEquals(0.3, dist.probability('g'), 1e-8);
		assertEquals(0.2, dist.probability('c'), 1e-8);
		assertEquals(0.1, dist.probability('a'), 1e-8);
		assertEquals(0.0, dist.probability('A'), 1e-8);
		assertEquals(0.0, dist.probability('B'), 1e-8);
		assertEquals(0.0, dist.probability('z'), 1e-8);
	}
	
	public void testNormalize() {
		CharacterDistribution dist = new CharacterDistribution();
		dist.set('a', 10.0);
		dist.set('c', 20.0);
		dist.set('g', 30.0);
		dist.set('t', 40.0);
		dist.normalize();
		assertEquals(0.4, dist.probability('t'), 1e-8);
		assertEquals(0.3, dist.probability('g'), 1e-8);
		assertEquals(0.2, dist.probability('c'), 1e-8);
		assertEquals(0.1, dist.probability('a'), 1e-8);
		assertEquals(0.0, dist.probability('A'), 1e-8);
		assertEquals(0.0, dist.probability('B'), 1e-8);
		assertEquals(0.0, dist.probability('z'), 1e-8);
	}

	public void testClone() {
		CharacterDistribution dist = new CharacterDistribution();
		dist.set('a', 0.1);
		dist.set('c', 0.2);
		dist.set('g', 0.3);
		dist.set('t', 0.4);		
		CharacterDistribution dist2 = dist.clone();
		assertEquals(0.1, dist.probability('a'), 1e-8);
		assertEquals(0.1, dist2.probability('a'), 1e-8);
		dist2.set('a', 0.2);
		assertEquals(0.1, dist.probability('a'), 1e-8);
		assertEquals(0.2, dist2.probability('a'), 1e-8);
	}
	
}
